package com.webtest.demo;

import java.util.List;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import bsh.This;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;

public class CrossearthPage {

	AndroidDriver  driver;
	BaseAction action;
	
	public CrossearthPage(AndroidDriver driver) {
		this.driver = driver;
		this.action= new BaseAction(driver);
	}

	//一、创作板块页面
	public WebElement copyLink() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/bu_go"));
	}	
	

	//二、追溯板块页面
	public WebElement historyToday(int i) {
		WebElement list=driver.findElement(AppiumBy
				.id("com.software.crossearth:id/history_today_recycler_view"));			
		List<WebElement> items=list.findElements(AppiumBy
				.className("android.widget.LinearLayout"));
		//获取当页第i个事件
		WebElement historytoday= items.get(i);
		return historytoday;
	};
	
	
	//三、简介模块页面
	public WebElement signatureIndividual() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='个性签名']"));
	}
	public WebElement checksignatureIndividual() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/edt_information_introduction"));
	}
	public WebElement save() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/bu_information_keep"));
	}

	

	//一、创作板块页面
	//41.查看创作模块能否正常打开
	public void openauthoringModules() throws InterruptedException {
		action.click(this.crossearth());
		action.click(this.startCrossearth());
		action.click(this.quickLogin());
		action.click(this.creation());
		action.click(this.copyLink());
	}
	
	
	//八、真知板块页面
	//42.查看创作模块能否正常打开
	public void opentruthModules() throws InterruptedException {
		action.click(historicalknowledge());
		action.swipe(354, 1386, 354, 311);	
	}
	
	//43.使用键盘方向键进行翻页操作
	public void keybordturnpagetruthmodule() throws InterruptedException {
		action.click(historicalknowledge());
		for(int i=0;i<9;++i) {
			action.pressTabKey();
			Thread.sleep(200);
		}
		action.pressEnterKey();
		Thread.sleep(200);
		action.navigateBack();
		
	}
	
	//44.使用鼠标单机事件进行查看第四个故事
	public void mouseclicktruthModules() throws InterruptedException {
		action.click(historicalknowledge());
		action.click(this.historicalEvents(5));
		action.navigateBack();
		action.click(this.trueknowledgebackMainPage());
		Thread.sleep(200);
	}
	
	//45.鼠标侧拉选择秦朝
	public void mousesidepulltruthModules() throws InterruptedException {
		//action.click(this.quickLogin());
		action.click(historicalknowledge());
		action.clickAndDrag(894, 693, 774, 693);
		Thread.sleep(300);
		action.click(this.trueknowledgeDynasty(6));
	}
	
	
	//二、追溯板块页面
	//46.使用鼠标单击事件进行查看
	public void mousesbackModules() throws InterruptedException {
		action.click(tracedBack());
		action.click(this.historyToday(0));
	}
	
	//47.使用键盘打开事件详情
	public void keybordbackModules() throws InterruptedException {
		action.click(tracedBack());
		for(int i=0;i<7;++i) {
			action.pressTabKey();
			Thread.sleep(200);
		}
		action.pressEnterKey();
		Thread.sleep(200);
	}
	
	//48.鼠标点击事件进入详情页面和退出操作
	public void mousesquitbackModules() throws InterruptedException {
		action.click(tracedBack());
		action.click(this.historyToday(3));
		action.navigateBack();		
	}


	//三、简介模块页面
	//49.个性签名输入特殊字符+字母+数字
	public void combineintroductoryModule() throws InterruptedException {
		//action.click(this.quickLogin());
		action.click(synopsis());
		action.typeAndClear(this.checksignatureIndividual(), "@#$ASgvc2345");		
		action.click(this.save());
	}
	
	//50.输入已经存在的个性签名
	public void existintroductoryModules() throws InterruptedException {		
		action.click(synopsis());
		action.typeAndClear(this.checksignatureIndividual(), "123");
		action.click(this.save());
	}

}